package com.yd.app.service.pc.evaluateService;

import com.yd.app.mapper.EvaluateMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.Evaluate;
import com.yd.domain.commom.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 评价Service
 * Created by sunxianhui on 2018/3/9.
 */
@Service
public class EvaluateService extends BaseService {
    @Autowired
    EvaluateMapper evaluateMapper;

    /**
     * 添加评价
     *
     * @param evaluate
     */
    public int addEvaluate(Evaluate evaluate) {
        return evaluateMapper.addEvaluate(evaluate);
    }

    /**
     * 修改
     *
     * @param evaluate
     */
    public void updateEvaluate(Evaluate evaluate) {
        evaluateMapper.updateEvaluate(evaluate);
    }

    /**
     * 删除
     *
     * @param id
     */
    public void deleteEvaluateByid(String id) {
        evaluateMapper.deleteEvaluateById(id);
    }

    /**
     * 根据条件分页查询
     * @param goodsId
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public PageModel getEvaluateList(String goodsId, int pageIndex, int pageSize) {
        PageModel pm = new PageModel();
        int startRow = getStartRow(pageIndex, pageSize);
        List<Evaluate> evaluateList = evaluateMapper.getEvaluateList(goodsId, startRow, pageSize);
        int count = 0;
        if (pageIndex == 1) {
            //查询总条数
            count = evaluateMapper.getEvaluateCount(goodsId);
            pm.setCount(count);
        }
        pm.setList(evaluateList);
        return pm;
    }
}